package com.gregbugaj.nscaffold.type;

import org.hibernate.type.CollectionType;
import org.hibernate.type.DoubleType;
import org.hibernate.type.IntegerType;
import org.hibernate.type.ManyToOneType;
import org.hibernate.type.OneToOneType;
import org.hibernate.type.StringType;
import org.hibernate.type.Type;

/**
 * Hibernate Type Resolver
 * @author gbugaj
 *
 */
public class HibernateTypeResolver implements TypeResolver<org.hibernate.type.Type> {

	@Override
	public PType resolve(Type type) {
		if (type instanceof StringType) {
			return PType.StringType;
		}else if (type instanceof IntegerType) {
			return PType.IntegerType;
		}else if (type instanceof DoubleType) {
			return PType.DoubleType;
		}
		else if (type instanceof OneToOneType) {
			return PType.OneToOneType;
		}
		else if (type instanceof ManyToOneType) {
			return PType.ManyToOneType;
		}
		else if (type instanceof CollectionType ) {
			return PType.CollectionType ;
		}
		
		return null;
	}

	@Override
	public boolean canResolve(Class<?> clazz) {
		if(clazz==null)return false;
		return (boolean)Type.class.isAssignableFrom(clazz);
	}

	

}
